<?php
/*
* @Created by Phpstorm
* @User: Zhangxinlei
* @Date: 
* @Time:
*/

namespace app\api\controller;

use think\Db;
use think\Request;

class Infor extends Base
{
    /**
     * @param Request $request
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function getInforList(Request $request)
    {
        $page = $request->param('pageNumber');
        $limit = $request->param('pageSize');
        $inforlist = Db::name('information')->page($page,$limit)->select();
        foreach ($inforlist as $key => $val){
            $inforlist[$key]['head_picture'] = 'http://106.55.6.120/staticResources/CcdVQP.png';
            $inforlist[$key]['nick_name'] = '我是张无敌';
        }
        return json(['code' => 200,'msg' => '获取成功','result'=>$inforlist]);
    }

    /**
     * @param Request $request
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * @content 动态列表
     */
    public function getDynameicList(Request $request){
        $page = $request->param('pageNumber');
        $limit = $request->param('pageSize');
        $field = "id,create_time, content, dy_img, thumbs_num,comment_num,is_ thumbs,is_block";
        $DynameicList = Db::name('dynamic')->field($field)->page($page,$limit)->select();
        foreach ($DynameicList as $key => $val){
            $DynameicList[$key]['dy_img'] = explode(',',$DynameicList[$key]['dy_img']);
            $DynameicList[$key]['head_picture'] = 'http://106.55.6.120/staticResources/CcdVQP.png';
            $DynameicList[$key]['nick_name'] = '我是张无敌';
        }
        return json(['code' => 200,'msg' => '获取成功','result'=>$DynameicList]);
    }
    /**
     * @param Request $request
     * @return \think\response\Json
     * @content 发布动态
     */
    public function getAddDynameic(Request $request){
        $data = $request->param();
        $data['create_time'] = time();
        if (Db::name('dynamic')->insert($data)){
            return json(['code' => 200,'msg' => '发布成功','result'=>$data]);
        }else{
            return json(['code' => 201,'msg' => '发布失败']);
        }
    }
}